package c3;


import java.util.function.Function;

/**
 * 测试函数复合，做写信流水线
 */
public class Letter {
    public static String addHeader(String text){
        return "From yh:"+text;
    }
    public static String addFooter(String text){
        return text + " Kind regards"; //亲切问候
    }
    public static String checkSpelling(String text){
        return text.replaceAll("lam","lambda");
    }

    public static void main(String[] args) {
        //第一种流水线
        Function<String, String> addHeader = Letter::addHeader;
        Function<String, String> transformationPipeline
                = addHeader.andThen(Letter::checkSpelling)
                .andThen(Letter::addFooter);
        String result1=transformationPipeline.apply("good good study,day day up.lam");
        System.out.println("第一种信："+result1);
        //第二种流水线
        Function<String, String> transformationPipeline2
                = addHeader.andThen(Letter::addFooter);
        String result2=transformationPipeline2.apply("good good study,day day up.lam");
        System.out.println("第二种信："+result2);
    }
}
